package com.vshop.utils;

import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * SHA加密代码
 */
public class SHA {

    private static BASE64Encoder encoder = new sun.misc.BASE64Encoder();

    public static String encrypt(String password) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA");
            // step 3
            md.update(password.getBytes("UTF-8"));
            // step 4
            byte raw[] = md.digest();
            // step 5
            String hash = (new BASE64Encoder()).encode(raw);
            // step 6
            return hash;
        } catch (NoSuchAlgorithmException e) {
        } catch (java.io.UnsupportedEncodingException e) {
        }
        return null;
    }

}